package com.springboot.middleware.middleware_redisson.server.redisson;

import org.redisson.api.RQueue;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class QueuePublisher {
    private static final Logger log = LoggerFactory.getLogger(QueuePublisher.class);

    @Autowired
    private RedissonClient redissonClient;

    public void sendBasicMsg(String msg) {
        try {
            final String queueName = "redissonBasicQueue";
            RQueue<String> queue = redissonClient.getQueue(queueName);
            queue.add(msg);
            log.info("队列的生产者 - 发送基本的消息 - 消息发送成功: {}", msg);
        } catch (Exception e) {
            log.error("队列的生产者 - 发送基本的消息 - 发生异常: {}", msg,e.fillInStackTrace());
        }
    }
}
